﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HA.MT3DMS.DomainLayer;
namespace HA.ModFlow.Controls.MT3DMSWindows
{
    /// <summary>
    /// winParticles.xaml 的交互逻辑
    /// </summary>
    public partial class winParticles : Window
    {
        public winParticles(Advection Adv,MTModelOption mdOption)
        {
            InitializeComponent();
            this._Adv =(Advection) Adv.Clone ();
            this.tbConcentration.Text = "单元相对浓度梯度阈值(" + HA.ModFlow.Domain.DomainLayer.UnitConverter.GetConcentration(mdOption.Units) + "):";
            this.tbGradient.Text = "MOC/MMOC选择的临界相对浓度梯度(" + HA.ModFlow.Domain.DomainLayer.UnitConverter.GetConcentration(mdOption.Units) + "):";
        }

        private Advection _Adv;

        public Advection Adv
        {
            get { return _Adv; }
         
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = this._Adv;


            //窗体对应的状态变化
            switch (this.Adv.SolutionScheme)
            {
                case AdvectionSolutionScheme.ThirdOrderTVD:
                    this.txtMXPART.IsEnabled = false;
                    this.txtDCEPS.IsEnabled = false;
                    this.cboNumberof.IsEnabled = false;
                    this.txtNPLANE.IsEnabled = false;
                    this.txtNPL.IsEnabled = false;
                    this.txtNPH.IsEnabled = false;
                    this.txtNPMIN.IsEnabled = false;
                    this.txtNPMAX.IsEnabled = false;
                    this.cboParticlesCells.IsEnabled = false ;
                    this.txtNLSINK.IsEnabled = false;
                    this.txtNPSINK.IsEnabled = false;
                    this.txtDCHMOC.IsEnabled = false;

                    //if (this.Adv.Numberof == NumberofPlances.RandomParticle)
                    //{
                    //    this.cboNumberof.SelectedIndex = 0;
                    //}
                    //else
                    //{
                    //    this.cboNumberof.SelectedIndex = 1;
                    //}
                    break;
                case AdvectionSolutionScheme.StandardFiniteDifference:
                    this.txtMXPART.IsEnabled = false;
                    this.txtDCEPS.IsEnabled = false;
                    this.cboNumberof.IsEnabled = false;
                    this.txtNPLANE.IsEnabled = false;
                    this.txtNPL.IsEnabled = false;
                    this.txtNPH.IsEnabled = false;
                    this.txtNPMIN.IsEnabled = false;
                    this.txtNPMAX.IsEnabled = false;
                    this.cboParticlesCells.IsEnabled = false ;
                    this.txtNLSINK.IsEnabled = false;
                    this.txtNPSINK.IsEnabled = false;
                    this.txtDCHMOC.IsEnabled = false;

                    //if (this.Adv.Numberof == NumberofPlances.RandomParticle)
                    //{
                    //    this.cboNumberof.SelectedIndex = 0;                     
                    //}
                    //else
                    //{
                    //    this.cboNumberof.SelectedIndex = 1;                      
                    //}
                    break;
                case AdvectionSolutionScheme.ModifiedMethodOfCharacteristics:
                    this.txtMXPART.IsEnabled = false;
                    this.txtDCEPS.IsEnabled = false;
                    this.cboNumberof.IsEnabled = false;
                    this.txtNPLANE.IsEnabled = false;
                    this.txtNPL.IsEnabled = false;
                    this.txtNPH.IsEnabled = false;
                    this.txtNPMIN.IsEnabled = false;
                    this.txtNPMAX.IsEnabled = false;
                    this.cboParticlesCells.IsEnabled = true;
                    this.txtNLSINK.IsEnabled = true;
                    this.txtNPSINK.IsEnabled = true;
                    this.txtDCHMOC.IsEnabled = true;

                    if (this.Adv.ParticlesCells == NumberofPlances.RandomParticle)
                    {
                        this.txtNLSINK.IsEnabled = false;
                      this.cboParticlesCells.SelectedIndex = 0;
                    }
                    else
                    {
                        this.txtNLSINK.IsEnabled = true;
                        this.cboParticlesCells.SelectedIndex = 1;
                    }
                 
                    break;
                case AdvectionSolutionScheme.MethodOfCharacteristics:
                    this.txtMXPART.IsEnabled = true;
                    this.txtDCEPS.IsEnabled = true;
                    this.cboNumberof.IsEnabled = true;
                    this.txtNPLANE.IsEnabled = true;
                    this.txtNPL.IsEnabled = true;
                    this.txtNPH.IsEnabled = true;
                    this.txtNPMIN.IsEnabled = true;
                    this.txtNPMAX.IsEnabled = true;
                    this.cboParticlesCells.IsEnabled = false ;
                    this.txtNLSINK.IsEnabled = false;
                    this.txtNPSINK.IsEnabled = false;
                    this.txtDCHMOC.IsEnabled = false;

                    if (this.Adv.Numberof == NumberofPlances.RandomParticle)
                    {
                        this.cboNumberof.SelectedIndex = 0;
                        this.txtNPLANE.IsEnabled = false;
                    }
                    else
                    {
                        this.cboNumberof.SelectedIndex = 1;
                        this.txtNPLANE.IsEnabled = true;
                    }
                    break;
                case AdvectionSolutionScheme.HbridMOCOrMMOC:
                    this.txtMXPART.IsEnabled = true;
                    this.txtDCEPS.IsEnabled = true;
                    this.cboNumberof.IsEnabled = true;
                    this.txtNPLANE.IsEnabled = true;
                    this.txtNPL.IsEnabled = true;
                    this.txtNPH.IsEnabled = true;
                    this.txtNPMIN.IsEnabled = true;
                    this.txtNPMAX.IsEnabled = true;
                    this.cboParticlesCells.IsEnabled = true;
                    this.txtNLSINK.IsEnabled = true;
                    this.txtNPSINK.IsEnabled = true;
                    this.txtDCHMOC.IsEnabled = true;

                    if (this.Adv.ParticlesCells == NumberofPlances.RandomParticle)
                    {
                        this.txtNLSINK.IsEnabled = false;
                        this.cboParticlesCells.SelectedIndex = 0;
                    }
                    else
                    {
                        this.txtNLSINK.IsEnabled = true;
                        this.cboParticlesCells.SelectedIndex = 1;
                    }

                    if (this.Adv.Numberof == NumberofPlances.RandomParticle)
                    {
                        this.cboNumberof.SelectedIndex = 0;
                        this.txtNPLANE.IsEnabled = false;
                    }
                    else
                    {
                        this.cboNumberof.SelectedIndex = 1;
                        this.txtNPLANE.IsEnabled = true;
                    }
                    break;
            }

         

        }

        private void cboNumberof_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.cboNumberof.SelectedIndex == 0)
            {
                this.txtNPLANE.IsEnabled = false;
                this.Adv.Numberof = NumberofPlances.RandomParticle;
            }
            else
            {
                this.txtNPLANE.IsEnabled = true;
                this.Adv.Numberof = NumberofPlances.FixedPattern;
            }
            
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }

        private void btnCancal_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void cboParticlesCells_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.cboParticlesCells.SelectedIndex == 0)
            {
                this.txtNLSINK.IsEnabled = false;
                this.Adv.ParticlesCells = NumberofPlances.RandomParticle;
            }
            else
            {
                this.txtNLSINK.IsEnabled = true;
                this.Adv.ParticlesCells = NumberofPlances.FixedPattern;
            }
        }
    }
}
